import request from '@/utils/request'

// 单文件上传
export function uploadFile(file) {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/files/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 批量文件上传
export function uploadFiles(files) {
  const formData = new FormData()
  files.forEach(file => {
    formData.append('files', file)
  })
  return request({
    url: '/files/upload/batch',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 获取文件信息
export function getFileInfo(fileId) {
  return request({
    url: `/files/${fileId}`,
    method: 'get'
  })
}

// 获取文件访问URL
export function getFileUrl(fileId) {
  return request({
    url: `/files/${fileId}/url`,
    method: 'get'
  })
}

// 删除文件
export function deleteFile(fileId) {
  return request({
    url: `/files/${fileId}`,
    method: 'delete'
  })
}

// 文件 API 对象
export const fileApi = {
  uploadFile,
  uploadFiles,
  getFileInfo,
  getFileUrl,
  deleteFile
}